package com.json;

import com.google.gson.Gson;

/**
 * @author guqiuxia
 *	@time Apr 1, 2017-1:10:44 PM
 * @description
 */
public class GsonDemo {
	public static void main(String[] args) {
		  String json = "{\"name\":\"chenggang\",\"age\":24}";
		  People bean1 = (People)GsonDemo.JSONToObject(json, People.class);
		  
		  System.out.println(bean1.getName());
	}
	
	public static Object JSONToObject(String json,Class beanClass) {
	    Gson gson = new Gson();
	    Object res = gson.fromJson(json, beanClass);
	    return res;
	}
	
	private static class People{
		private String name;
		private String age;
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getAge() {
			return age;
		}
		public void setAge(String age) {
			this.age = age;
		}
		public People() {
			super();
			// TODO Auto-generated constructor stub
		}
	}
}
